import Mock from 'mockjs';
import { LOCAL_KEY } from '@/constant/dict';
import { version } from 'vue-i18n';
import storage from '@/utils/storage';
import { data } from 'browserslist';
import { result } from 'lodash-es';
import qs from 'qs';


// 新增：form-urlencoded 字符串转对象的函数
function parseFormUrlEncoded(str) {
  return str.split('&').reduce((acc, cur) => {
    const [key, value] = cur.split('=');
    acc[decodeURIComponent(key)] = decodeURIComponent(value);
    return acc;
  }, {});
}

 // 随机步长生成函数
    function getRandomStep(min = 1, max = 5) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }
// 随机速率生成函数
function getRandomRate(min = 1, max = 30) {
    // 生成带小数的随机数，保留1位小数
    return parseFloat((Math.random() * (max - min) + min).toFixed(1));
}

// 模拟登录尝试次数和锁定状态
let loginAttempts = 3;
let lockoutEndTime = null;
const validKeys = ['003100320033003400350036003700380070'];

// 模拟已生成的 Token 及其失效时间
const generatedTokens = {};

Mock.mock('/api/auth/login', 'post', (options) => {
    console.log('Mock调用: 登录');
    let password = "";
    try { 
        console.log('登录参数:', options);
        let params = qs.parse(options.body);
        console.log('登录参数:', params);
        password = params.password;
    } catch (error) {
        console.log('登录过程出错:', error);
        return {
            code: 1,
            message: '登录失败'
        };
    }
    
    if (validKeys.includes(password)) {
        const token = Mock.Random.guid();
        const expirationTime = new Date().getTime() + 3600 * 1000; // 1小时后过期
        generatedTokens[token] = expirationTime;
        return {
            code: 0,
            data: {
                token: token,
            },
        };
    } else {    
        return {
            code: 1,
            message: 'Invalid key',
        };
    }

    //  if (password) {
    //     const token = Mock.Random.guid();
    //     const expirationTime = new Date().getTime() + 3600 * 1000; // 1小时后过期
    //     generatedTokens[token] = expirationTime;
    //     return {
    //         code: 0,
    //         data: {
    //             token: token,
    //         },
    //     };
    // } else {
    //     return {
    //         code: 401,
    //         message: 'Invalid key',
    //     };
    // }
});

// 模拟token 验证
Mock.mock('/api/auth/verify', 'post', (options) => { 
    const token = options.headers.Authorization?.split(' ')[1];
    if (token && generatedTokens[token]) {
        const currentTime = new Date().getTime();
        if (currentTime < generatedTokens[token]) {
        return {
            code: 0,
            message: 'Token is valid',
        };
        } else {
        delete generatedTokens[token]; // 删除过期的 Token
        return {
            code: 401,
            message: 'Token has expired',
        };
        }
    } else {
        return {
        code: 401,
        message: 'Token is invalid',
        };
    }
});

// 模拟获取用户分组
Mock.mock('/api/group', 'get', () => {
    console.log("Mock调用: 获取用户分组");
    return {
        code: 0,
        data: 'admin'
    };
});

// 模拟退出登录
Mock.mock('/api/auth/logout', 'post', (options) => {
    console.log('Mock调用: 退出登录');
    
    // 清除登录状态
    localStorage.removeItem(LOCAL_KEY.IS_AUTH_TOKEN);
    
    const token = options.headers.Authorization?.split(' ')[1];
    if (token && generatedTokens[token]) {
        delete generatedTokens[token];
        return {
        code: 200,
        message: 'Logged out successfully',
        };
    } else {
        return {
        code: 401,
        message: 'Token is invalid',
        };
    }
});


// 原始短信数据，包含Device和SIM类型
const rawSmsList = [
    {
        "id": "1",
        "haveUnread": true,
        "isPhoneBook": true,
        "name": "张三",
        "number": "13800138000",
        "count": 3,
        "content": "你好，请问明天有空吗？",
        "status": 1,
        "ids": 1,
        "date": "2023-10-01 14:30",
        "type": "Device"
    },
    {
        "id": "2",
        "haveUnread": false,
        "isPhoneBook": false,
        "name": "李四",
        "number": "13900139000",
        "count": 1,
        "content": "会议安排在下午3点",
        "status": 2,
        "ids": 2,
        "date": "2023-10-02 09:15",
        "type": "Device"
    },
    {
        "id": "3",
        "haveUnread": true,
        "isPhoneBook": true,
        "name": "王五",
        "number": "13700137000",
        "count": 5,
        "content": "<span style='color:red'>紧急！请尽快回复</span>",
        "status": 1,
        "ids": 3,
        "date": "2023-10-03 16:45",
        "type": "SIM"
    },
    {
        "id": "4",
        "haveUnread": false,
        "isPhoneBook": true,
        "name": "赵六",
        "number": "13600136000",
        "count": 2,
        "content": "系统通知：您的套餐已更新",
        "status": 1,
        "ids": 4,
        "date": "2023-10-04 10:20",
        "type": "SIM"
    }
]

// 模拟sms信息
Mock.mock('/api/sms/list', 'get', () => {
    console.log("Mock调用: sms信息");

    // 按照formatData函数需要的结构处理数据
    const responseData = {
        Device_message_list: rawSmsList.filter(item => item.type === "Device"),
        Sim_message_list: rawSmsList.filter(item => item.type === "SIM")
    // phonebook_list: [  // 添加通讯录数据，与短信数据关联
    //   { id: "1", name: "张三", number: "13800138000" },
    //   { id: "2", name: "李四", number: "13900139000" },
    //   { id: "3", name: "王五", number: "13700137000" },
    //   { id: "4", name: "赵六", number: "13600136000" }
    // ]
    };
    console.log("responseData:" + JSON.stringify(responseData));

    return {
        code: 0,
        data: JSON.stringify(responseData)
    };
});

// 模拟删除短信接口
Mock.mock('/api/sms/delete', 'post', (options) => {
    console.log("Mock删除短信请求:", options);

    try {
        const params = JSON.parse(options.body);
        const { ids, storage } = params;

        return {
            code: 0,
            result: 'success',
            message: '删除成功',
            data: {
                deletedIds: ids,
                storage: storage
            }
        };
    } catch (error) {
        return {
            code: -1,
            result: 'error',
            message: '删除失败，参数解析错误'
        };
    }
});

// 模拟删除全部短信接口（区分设备/SIM）
Mock.mock('/api/sms/deleteall', 'post', (options) => {
    try {
        const params = JSON.parse(options.body);
        const { storage } = params;

        return {
            code: 0,
            result: 'success',
            message: `成功清空${storage === '1' ? '设备' : 'SIM'}卡短信`,
            data: {
                storage: storage,
            }
        };
    } catch (error) {
        return {
            code: -1,
            result: 'error',
            message: '清空失败'
        };
    }
});

//模拟aboutInfo
const mockAboutInfo = {
    // WiFi MAC 地址（2.4G/5G/6G）
    'wifi2gMac': 'A1B2C3D4E5F6',          // 2.4G MAC
    'wifi5gMac': 'A7B8C9D0E1F2',        // 5G MAC
    'wifi6gMac': 'A3B4C5D6E7F8',             // 6G MAC
    // 设备标识信息
    'imei': '123456789012345', // IMEI
    'imeiDouble': '123456789012345,678901234567890', // 双 IMEI（082 专用）
    'imeiSv': '310150123456789',  // IMSI
    'iccid': '89860012345678901234', // ICCID
    'eid': 'EID1234567890ABCDEF',     // EID
    // 设备基础信息
    'manufacturer': '高通',      // 制造商
    'modelName': '5G CPE Pro',  // 型号名称
    'modelnumber': 'QDM-546',   // 型号编号
    'serial': 'SN123456789',         // 序列号
    'hardWare': 'V1.0',                // 硬件版本
    // 固件信息
    'deviceUptime': '86400',              // 运行时间（秒）
    // 网络信息
    'wanIp': '192.168.1.100', // WAN IP
    'wanIpv6': '2001:db8::1',      // WAN IPv6
    'wanOrLanIp': '00:1A:2B:3C:4D:5E', // WAN/LAN MAC
    // 电话号码
    'phoneNumber': '13800138000'  // MSISDN
}

Mock.mock('/api/system/about', 'get', () => {
    console.log("Mock调用: about信息");
    return {
        code: 0,
        data: mockAboutInfo
    };
});

// 模拟安全
Mock.mock('/api/security/ipfilter', 'get', () => {
    console.log("Mock调用: security信息");
    return {
        code: 0,
        data: {
            // IP 过滤相关配置
            ipFilter: {
                enabled: true,  // 是否启用IP过滤
                policy: 'allow', // 过滤模式: allow/deny
                rules: [
                    { id: '1', ip: '192.168.1.100' },
                    { id: '2', ip: '192.168.1.101' },
                    { id: '3', ip: '192.168.1.102' }
                ],
                maxRules: 32  // 最大规则数
            },
            // 防火墙状态
            firewall: {
                enabled: true,
                level: 'medium' // low/medium/high
            },
            // 其他安全相关配置
            portForwarding: {
                enabled: false
            },
            dmz: {
                enabled: false,
                host: ''
            },
            // 安全日志
            securityLogs: {
                enabled: true,
                retentionDays: 30
            }
        }
    };
});

// 模拟获取 IP 过滤列表
Mock.mock('/api/security/LIST_IP_FILTER', 'get', () => {
    console.log("Mock调用: 获取IP过滤列表");
    return {
        code: 0,
        data: [
            { 
                id: '1', 
                filterListIp: '192.168.1.100' 
            },
            { 
                id: '2', 
                filterListIp: '192.168.1.101' 
            },
            { 
                id: '3', 
                filterListIp: '192.168.1.102' 
            }
        ]
    };
});

// IP过滤策略
Mock.mock('/api/security/setipnode', 'post', (options) => { 
    console.log("Mock调用: 设置IP过滤策略", options.body);
    const { policy } = JSON.parse(options.body); // 解析请求参数

    return {
        code: 0,
        result: 'success',
        message: `策略模式已更新为 ${policy}`,
        data: {
            updatedPolicy: policy
        }
    };
});

// 新增IP
Mock.mock('/api/security/addip', 'post', (options) => {
    console.log("Mock调用: 添加IP过滤规则", options.body);

    try {
        const params = JSON.parse(options.body);
        const { ip } = params;

        // Validate IP format
        if (!/^(\d{1,3}\.){3}\d{1,3}$/.test(ip)) {
            return {
                code: -1,
                result: 'error',
                message: '无效的IP地址格式'
            };
        }

        // 检查重复（模拟服务器端检查）
        const currentIps = [
            { id: '1', filterListIp: '192.168.1.100' },
            { id: '2', filterListIp: '192.168.1.101' },
            { id: '3', filterListIp: '192.168.1.102' }
        ].map(rule => rule.filterListIp);
        
        if (currentIps.includes(ip)) {
            return {
                code: -2,
                result: 'error',
                message: 'IP地址已存在'
            };
        }

        // 模拟成功添加
        return {
            code: 0,
            result: 'success',
            message: 'IP添加成功',
            data: {
                id: Mock.Random.guid(),
                ip: ip,
                createdAt: new Date().toISOString()
            }
        };
    } catch (error) {
        return {
            code: -1,
            result: 'error',
            message: '参数解析失败'
        };
    }
});

// 编辑IP过滤规则
Mock.mock('/api/security/editip', 'post', (options) => {
    console.log("Mock调用: 编辑IP过滤规则", options.body);

    try {
        const params = JSON.parse(options.body);
        const { id, ip } = params;

        // 验证IP格式
        if (!/^(\d{1,3}\.){3}\d{1,3}$/.test(ip)) {
            return {
                code: -1,
                result: 'error',
                message: '无效的IP地址格式'
            };
        }

        // 模拟重复检查
        const existingIps = [
            { id: '1', filterListIp: '192.168.1.100' },
            { id: '2', filterListIp: '192.168.1.101' },
            { id: '3', filterListIp: '192.168.1.102' }
        ];

        // 检查是否有其他项使用了相同的IP
        const isDuplicate = existingIps.some(item => 
            item.id !== id && item.filterListIp === ip
        );
        
        if (isDuplicate) {
            return {
                code: -2,
                result: 'error',
                message: 'IP地址已存在'
            };
        }

        // 模拟成功响应
        return {
            code: 0,
            result: 'success',
            message: 'IP编辑成功',
            data: {
                id: id,
                ip: ip,
                updatedAt: new Date().toISOString()
            }
        };
    } catch (error) {
        return {
            code: -1,
            result: 'error',
            message: '参数解析失败'
        };
    }
});

// 删除IP
Mock.mock('/api/security/delip', 'post', (options) => {
    console.log("Mock调用: 删除IP规则", options.body);
    
    try {
        const params = JSON.parse(options.body);
        const { id } = params;

        // 模拟的IP列表
        const mockIpList = [
            { id: '1', filterListIp: '192.168.1.100' },
            { id: '2', filterListIp: '192.168.1.101' },
            { id: '3', filterListIp: '192.168.1.102' }
        ];

        // 检查IP是否存在
        const ipExists = mockIpList.some(item => item.id === id);
        
        if (!ipExists) {
            return {
                code: -1,
                result: 'error',
                message: 'IP规则不存在'
            };
        }

        // 模拟成功删除
        return {
            code: 0,
            result: 'success',
            message: 'IP删除成功',
            data: {
                deletedId: id,
                remainingCount: mockIpList.length - 1
            }
        };
    } catch (error) {
        return {
            code: -1,
            result: 'error',
            message: '参数解析失败'
        };
    }
});

// accessControl
// 模拟访问控制数据存储
let mockAccessControlList = [
    {
        id: '1',
        fw_rule_alias: 'Web访问',
        fw_rule_source_ip: '192.168.1.100',
        fw_rule_dest_ip: 'any',
        fw_rule_source_port: 'any',
        fw_rule_dest_port: '80,443',
        fw_rule_target: 'Accept',
        fw_rule_protocol: 'TCP',
        fw_rule_ipversion: '4',
        fw_rule_order: '1',
        fw_rule_source_port_rangemax: '',
        fw_rule_dest_port_rangemax: ''
    },
    {
        id: '2',
        fw_rule_alias: 'SSH限制',
        fw_rule_source_ip: 'any',
        fw_rule_dest_ip: '192.168.1.1',
        fw_rule_source_port: 'any',
        fw_rule_dest_port: '22',
        fw_rule_target: 'Reject',
        fw_rule_protocol: 'TCP',
        fw_rule_ipversion: '4',
        fw_rule_order: '2',
        fw_rule_source_port_rangemax: '',
        fw_rule_dest_port_rangemax: ''
    }
];

// 获取访问控制列表 get
Mock.mock('/api/security/accesscontrol', 'get', () => {
    console.log("Mock调用: 获取访问控制列表");
    return {
        code: 0,
        data: {
            enabled: true,
            maxRules: 32, // 最大规则数
            list: mockAccessControlList
        }
    };
});

// 添加访问控制规则 add
Mock.mock('/api/security/accesscontrol/add', 'post', (options) => {
    console.log("Mock调用: 添加访问控制规则", options.body);

    try {
        const params = JSON.parse(options.body);

        // 验证必填字段
        if (!params.fw_rule_alias) {
            return {
                code: -1,
                result: 'error',
                message: '规则名称不能为空'
            };
        }

        // 检查规则数量是否超过限制
        if (mockAccessControlList.length >= 32) {
            return {
                code: -2,
                result: 'error',
                message: '已达到最大规则数限制(32条)'
            };
        }

        // 生成新规则ID
        const newRule = {
            id: Mock.Random.guid(),
            ...params,
            createdAt: new Date().toISOString(),
            updatedAt: new Date().toISOString()
        };

        // 添加到模拟数据
        mockAccessControlList.push(newRule);

        return {
            code: 0,
            result: 'success',
            message: '访问控制规则添加成功',
            data: newRule
        };
    } catch (error) {
        return {
            code: -1,
            result: 'error',
            message: '参数解析失败: ' + error.message
        };
    }
});

// 更新访问控制规则 update
Mock.mock('/api/security/accesscontrol/update', 'post', (options) => {
    console.log("Mock调用: 更新访问控制规则", options.body);

    try {
        const params = JSON.parse(options.body);
        const { id } = params;

        // 查找要更新的规则
        const index = mockAccessControlList.findIndex(item => item.id === id);
        if (index === -1) {
            return {
                code: -1,
                result: 'error',
                message: '规则不存在'
            };
        }

        // 更新规则
        mockAccessControlList[index] = {
            ...mockAccessControlList[index],
            ...params,
            updatedAt: new Date().toISOString()
        };

        return {
            code: 0,
            result: 'success',
            message: '访问控制规则更新成功',
            data: mockAccessControlList[index]
        };
    } catch (error) {
        return {
            code: -1,
            result: 'error',
            message: '参数解析失败'
        };
    }
});

// 删除访问控制规则 del
Mock.mock('/api/security/accesscontrol/del', 'post', (options) => {
    console.log("Mock调用: 删除访问控制规则", options.body);

    try {
        const params = JSON.parse(options.body);
        const { id } = params;

        // 查找要删除的规则
        const index = mockAccessControlList.findIndex(item => item.id === id);
        if (index === -1) {
            return {
                code: -1,
                result: 'error',
                message: '规则不存在'
            };
        }

        // 删除规则
        const [deletedRule] = mockAccessControlList.splice(index, 1);

        return {
            code: 0,
            result: 'success',
            message: '访问控制规则删除成功',
            data: deletedRule
        };
    } catch (error) {
        return {
            code: -1,
            result: 'error',
            message: '参数解析失败'
        };
    }
});

// mac
// 模拟MAC过滤数据存储
let mockMacList = [
    {
        id: '1',
        list_dev_host_ac_iidstack: '1',
        list_dev_host_ac_phys_address: '00:11:22:33:44:55',
        list_dev_host_ac_host_name: 'MyPC',
        list_dev_host_ac_enable: '1',
        list_dev_host_ac_access_policy: 'Allow'
    },
    {
        id: '2',
        list_dev_host_ac_iidstack: '2',
        list_dev_host_ac_phys_address: 'AA:BB:CC:DD:EE:FF',
        list_dev_host_ac_host_name: 'MyPhone',
        list_dev_host_ac_enable: '1',
        list_dev_host_ac_access_policy: 'Deny'
    }
];

// 获取MAC过滤信息
Mock.mock('/api/mac/list', 'get', () => {
    console.log("Mock调用: 获取MAC过滤信息");
    return {
        code: 0,
        data: mockMacList
    };
});

// 获取已连接设备列表
Mock.mock('/api/mac/deviceslist', 'get', () => {
    console.log("Mock调用: 获取已连接设备列表");
    return {
        code: 0,
        data: [
            {
                id: '1',
                list_conn_dev_status: 'Online',
                list_conn_dev_hostname: 'iPhone',
                list_conn_dev_ip: '192.168.1.100',
                list_conn_dev_mac: '00:11:22:33:44:55'
            },
            {
                id: '2',
                list_conn_dev_status: 'Online',
                list_conn_dev_hostname: 'Android',
                list_conn_dev_ip: '192.168.1.101',
                list_conn_dev_mac: 'AA:BB:CC:DD:EE:FF'
            }
        ]
    };
});

// 更新MAC过滤规则
Mock.mock('/api/mac/set', 'post', (options) => {
    console.log("Mock调用: 更新MAC过滤规则", options.body);

    try {
        const params = JSON.parse(options.body);
        const { id, mac, hostname, active, mode } = params;

        // 查找要更新的规则
        const index = mockMacList.findIndex(item => item.id === id);
        if (index === -1) {
            return {
                code: -1,
                result: 'error',
                message: '规则不存在'
            };
        }

        // 验证MAC地址格式
        const macReg = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/;
        if (!macReg.test(mac)) {
            return {
                code: -2,
                result: 'error',
                message: '无效的MAC地址格式'
            };
        }

        // 更新规则
        mockMacList[index] = {
            ...mockMacList[index],
            list_dev_host_ac_phys_address: mac,
            list_dev_host_ac_host_name: hostname,
            list_dev_host_ac_enable: active,
            list_dev_host_ac_access_policy: mode
        };

        return {
            code: 0,
            result: 'success',
            message: 'MAC规则更新成功',
            data: mockMacList[index]
        };
    } catch (error) {
        return {
            code: -1,
            result: 'error',
            message: '参数解析失败'
        };
    }
});

// 添加MAC过滤规则
Mock.mock('/api/mac/add', 'post', (options) => {
    console.log("Mock调用: 添加MAC过滤规则", options.body);

    try {
        const params = JSON.parse(options.body);
        const { mac, hostname, active, mode } = params;

        // 检查规则数量是否超过限制
        if (mockMacList.length >= 32) {
            return {
                code: -3,
                result: 'error',
                message: '已达到最大规则数限制(32条)'
            };
        }

        // 验证MAC地址格式
        const macReg = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/;
        if (!macReg.test(mac)) {
            return {
                code: -2,
                result: 'error',
                message: '无效的MAC地址格式'
            };
        }

        // 检查MAC地址是否已存在
        if (mockMacList.some(item => item.list_dev_host_ac_phys_address === mac)) {
            return {
                code: -4,
                result: 'error',
                message: 'MAC地址已存在'
            };
        }

        // 生成新规则
        const newId = (mockMacList.length + 1).toString();
        const newRule = {
            id: newId,
            list_dev_host_ac_iidstack: newId,
            list_dev_host_ac_phys_address: mac,
            list_dev_host_ac_host_name: hostname,
            list_dev_host_ac_enable: active,
            list_dev_host_ac_access_policy: mode
        };

        mockMacList.push(newRule);

        return {
            code: 0,
            result: 'success',
            message: 'MAC规则添加成功',
            data: newRule
        };
    } catch (error) {
        return {
            code: -1,
            result: 'error',
            message: '参数解析失败'
        };
    }
});

// 删除MAC过滤规则
Mock.mock('/api/mac/del', 'post', (options) => {
    console.log("Mock调用: 删除MAC过滤规则", options.body);

    try {
        const params = JSON.parse(options.body);
        const { id } = params;

        // 查找要删除的规则
        const index = mockMacList.findIndex(item => item.id === id);
        if (index === -1) {
            return {
                code: -1,
                result: 'error',
                message: '规则不存在'
            };
        }

        // 删除规则
        const [deletedRule] = mockMacList.splice(index, 1);

        return {
            code: 0,
            result: 'success',
            message: 'MAC规则删除成功',
            data: {
                id: deletedRule.id,
                remainingCount: mockMacList.length
            }
        };
    } catch (error) {
        return {
            code: -1,
            result: 'error',
            message: '参数解析失败'
        };
    }
});

// devicemanagement
// 模拟设备重启
Mock.mock('/api/devicemanagement/reboot', 'post', (options) => {
    console.log("Mock调用: 设备重启", options.body);
    
    // 模拟重启延迟
    const delay = 5000; // 5秒延迟
    
    return {
        code: 0,
        result: 'success',
        message: '设备将在5秒后重启',
        data: {
            id: Mock.Random.guid(),
            delay: delay
        }
    };
});

// reset
Mock.mock('/api/devicemanagement/reset', 'post', (options) => {
    console.log("Mock调用: 设备恢复出厂设置", options.body);
    
    // 模拟恢复出厂设置需要3分钟（180秒）
    const delay = 180; 
    
    return {
        code: 0,
        result: 'success',
        message: '设备正在恢复出厂设置',
        data: {
            id: Mock.Random.guid(), // 生成唯一ID
            delay: delay,
            resetTime: new Date().getTime() + delay * 1000 // 计算预计完成时间
        }
    };
});

// connected devices
// Add to index.js in the Mock.mock section
Mock.mock('/api/connecteddevices/list', 'get', () => {
    console.log("Mock调用: 获取已连接设备列表");
    
    // Generate random devices with different types
    const deviceTypes = [0, 1, 3, 4]; // 0: 2.4G, 1: 5G, 3: 6G, 4: Wi-Fi7 MLO
    const statuses = ['Online', 'Offline'];
    
    const devices = Array.from({length: 8}, (_, i) => {
        const type = deviceTypes[Math.floor(Math.random() * deviceTypes.length)];
        const status = statuses[Math.floor(Math.random() * statuses.length)];
        
        return {
            id: `device_${i+1}`,
            list_conn_dev_hostname: `Device ${i+1}`,
            list_conn_dev_ip: `192.168.1.${100 + i}`,
            list_conn_dev_ipv6: `2001:db8::${100 + i}`,
            list_conn_dev_mac: `00:1A:2B:3C:4D:${i.toString(16).toUpperCase()}${(i+1).toString(16).toUpperCase()}`,
            list_conn_dev_status: status,
            list_conn_dev_ssid: type === 4 ? 'WiFi7_Network' : type === 3 ? '6G_Network' : type === 1 ? '5G_Network' : '2.4G_Network',
            list_conn_dev_devtype: type.toString()
        };
    });
    
    return {
        code: 0,
        data: devices
    };
});

// 修改WiFi Config的mock实现
Mock.mock(/api\/wireless\/config.*?/, 'get', (req) => {
    // 解析URL参数
    console.log("参数:", req);
    const type = "24"; // 获取type参数 ('2.4G', '5G', '6G')
    
    // 频段特定配置
    const allBandConfigs = [
        {
            type: '24',
            ssid: 'MyWiFi_2.4G',
            hide: '0',
            encryption: 'wpa2aes',
            encryption_list:[
                {
                    value: 'wpa2aes',
                    label: 'WPA2 AES'
                },
                {
                    value: 'wpa2psk',
                    label: 'WPA2 PSK'
                },
                {
                    value: 'wpa3psk',
                    label: 'WPA3 PSK'
                },
                {
                    value: 'wpa2wpa3psk',
                    label: 'WPA2/WPA3 PSK'
                }
            ],
            key: 'password123',
            channel: 6,
            bandwidth: 20,
            enable: true,
            channels: {
                20: '1,2,3,4,5,6,7,8,9,10,11,12,13',
                40: '1,2,3,4,5,6,7,8,9'
            },
            maxsta:8,
            defmax: 16,
        },
        {
            type: '5',
            ssid: 'MyWiFi_5G',
            hide: '0',
            encryption: 'wpa2aes',
            key: 'password123',
            encryption_list:[
                {
                    value: 'wpa2aes',
                    label: 'WPA2 AES'
                },
                {
                    value: 'wpa2psk',
                    label: 'WPA2 PSK'
                },
                {
                    value: 'wpa3psk',
                    label: 'WPA3 PSK'
                },
                {
                    value: 'wpa2wpa3psk',
                    label: 'WPA2/WPA3 PSK'
                }
            ],
            channel: 6,
            bandwidth: 80,
            enable: true,
            channels: {
                20: '36,40,44,48,52,56,60,64,100,104,108,112,116,120,124,128,132,136,140,144,149,153,157,161,165',
                40: '36,44,52,60,100,108,116,124,132,140,149,157',
                80: '36,52,100,116,132,149',
                160: '36,100'
            },
            defmax: 16,
            maxsta:16
        }
    ];

    return {
        code: 0,
        data: type === 24 ? allBandConfigs[0] : allBandConfigs[0]
    };
});



// 模拟WiFi状态控制接口
Mock.mock('/api/wireless/status', 'post', (options) => {
    const params = qs.parse(options.body);
    console.log("Mock参数:", params);
    // 根据请求参数返回不同的响应
    if (params.enable === "true" || params.enable === "false") {
        return {
            code: 0,
            message: 'WiFi状态设置成功',
            data: {
                enable: params.enable,
                updatedAt: new Date().toISOString()
            }
        };
    } else {
        return {
            code: -1,
            message: '无效的WiFi状态参数'
        };
    }
});

// WiFi表单提交
Mock.mock('/api/wireless/config', 'post', (options) => {
    console.log("Mock调用: WiFi配置提交", options.body);
    const params = JSON.parse(options.body);
    
    // 验证必填字段
    if (!params.ssid || (params.encryption !== 'none' && !params.password)) {
        return {
            code: -1,
            result: 'error',
            message: 'SSID和密码(非开放式)为必填项'
        };
    }

    // 验证密码长度
    if (params.encryption !== 'none' && params.password.length < 8) {
        return {
            code: -2,
            result: 'error',
            message: '密码长度至少8个字符'
        };
    }

    // 模拟成功响应
    return {
        code: 0,
        result: 'success',
        message: 'WiFi配置保存成功',
        data: {
            ...params,
            updatedAt: new Date().toISOString()
        }
    };
});


// 模拟其他必要的请求
// Mock.mock(RegExp('/api/node[^]*'), 'post', (options) => {
// console.log('捕获到未特定定义的node请求:', options.url);
// return {
//     code: 0,
//     data:{}
// };
// });

Mock.mock('/api/system/config', 'get', (params) => {
    console.log('Mock调用: 获取系统配置');
    return {
        code: 0,
        data: {
            'isWizard': false, // 是否是引导模式
            'is2_4g_enable': true,
            'is5g_enable': true,
            'is6g_enable': false,
            'main_status': 'connected',
        }
    };
});

Mock.mock('/api/system/language', 'get', (params) => {
    return {
        code: 0,
        data: 'zh'
    };
});

Mock.mock('/api/system/language', 'post', (params) => {
    console.log(params);
    return {
        code: 0,
        data: ''
    };
});

// mock battery
Mock.mock('/api/battery', 'get', () => {
console.log('Mock调用: 获取电池信息');
return {
    code: 0,
    data:{
        remaining_charge: 100,
        status: 'normal',
        sleep_time: 300,
        power_saving_mode  :false,  // 省点模式是否开启
        wifi_auto_disable_time:30 // 分钟
    }
};
});

// mock save battery
Mock.mock('/api/battery', 'post', (params) => {
console.log('Mock调用: 保存电池信息', JSON.parse(params.body));
return {
    code: 0,
    message: '保存成功'
};
});

Mock.mock('/api/system/time', 'get', () => {
    console.log('Mock调用: 获取系统时间');
    return {
        code: 0,
        data: {
            time: '2025-05-18 03:48:29',
        }
    };
});

var delay = 0; // 10此

Mock.mock('/api/system/version', 'get', () => {
    console.log('Mock调用: 获取系统版本');
    if(delay <=0){
        return {
            code: 0,
            data: {
                version: 'V06T003',
                storage: '32G',
                storage_available: '20G',
                auto_update: 0,
            }
        };
    }else{
        delay --;
        return {
            code: 2,
            data: {
                version: 'V06T003',
                storage: '32G',
                storage_available: '20G',
            }
        };
    }
});

Mock.mock("/api/system/fota", 'post', (options) => {
    return {
        code:0,
        data:''
    }
})

Mock.mock("/api/system/fota/auto", 'post', (options) => {
    console.log("Mock调用: 设置自动升级", JSON.parse(options.body));
    return {
        code:0,
        data:''
    }
})

Mock.mock("/api/system/fota/version", 'get', (options) => {
    return {
        code: 0,
        data: {
            version: 'V06T004',
            size: '798M'
        }
    }
})

var downloadProgress = 0;

Mock.mock('/api/system/fota/download', 'get', (options) => {
    downloadProgress += 2;
    return {
        code: 0,
        data: {
            progress: downloadProgress,
            path: 'D:/ota/V06T004.bin'
        }
    }
})

Mock.mock('/api/system/fota/download', 'post', (options) => {
    downloadProgress = 0;
    return {
        code: 0,
        data: ""
    }
})

Mock.mock('/api/system/upload', 'post', (options) => { 
    console.log('Mock调用: 上传文件',options.body);
    return {
        code:0,
        data:{
            path: '/upload/2023/05/05/update.zip'
        }
    }
})

Mock.mock('/api/system/upgrade', 'post', (options) => { 
    console.log('Mock调用: 升级系统');
    delay = 15;
    return {
        code:0,
        data:"调用成功"
    }
});


/**
 * 
 * DOWNLOADING = 3
 * VERIFYING = 4
 * FINALIZING = 5
 * UPDATED_NEED_REBOOT = 6
 */
var currentStatus = 3;
var currentUpgradeProgress = 0;
var error_code = 0;
Mock.mock('/api/system/upgrade','get',(options)=>{
    if(currentUpgradeProgress >=100){
        currentStatus ++;
        currentUpgradeProgress = 0;
    }else{
        currentUpgradeProgress += 5;
    }
    if(currentUpgradeProgress == 88){
        error_code = 200
    }
    return {
        code:0,
        data:{
            status: currentStatus,
            present:currentUpgradeProgress,
            error_code:error_code,
        }
    }
})

// mock gettime
Mock.mock('/api/time/system', 'get', () => { 
    console.log('Mock调用: 获取时间信息');
    return {
        code: 0,
        data: {
            time: '2023-05-09T08:05:05.000Z',
            timezone: 'MART+09:30',
            hour_24:true,
            master_ntp_server:'ntp.aliyun.com',
            slave_ntp_server:'11ntp.aliyun.com',
        }
    };
});

Mock.mock('/api/system/backup', 'get', () => {
    console.log('Mock调用: 下载backup文件');
    // 返回文件流
    const file = new Blob(['backup file content'], { type: 'application/octet-stream' });
    return {
        code: 0,
        data: {
            file: file
        }
    };
})

Mock.mock('/api/system/restore/upload', 'post', (params) => {
    console.log('Mock调用: 上传restore文件', params);
    return {
        code: 0,
        data: {
            path: 'D:/ota/V06T004.bin'
        }
    }
})

Mock.mock('/api/system/restore', 'post', (params) => {
    console.log('Mock调用: 触发restore', params);
    return {
        code: -13,
        data: ""
    }
})

Mock.mock('/api/time/system', 'post', (params) => {
console.log('Mock调用: 保存时间信息',  JSON.parse(params.body));
return {
    code: 0,
    message: '保存成功'
};
});

// mock gettimezone
Mock.mock('/api/time/zone', 'get', () => {
console.log('Mock调用: 获取时区信息');
return {
    code: 0,
    params: [
        { "id": "(GMT-12:00)International Date Line West", "value": "UTC+12:00" },
        { "id": "(GMT-11:00)Coordinated Universal Time-11", "value": "UTC+11:00" },
        { "id": "(GMT-10:00)Aleutian Islands", "value": "HAST+10:00" },
        { "id": "(GMT-10:00)Hawaii", "value": "HST+10:00" },
        { "id": "(GMT-09:30)Marquesas Islands", "value": "MART+09:30" }
    ]
};
});

Mock.mock('/api/kernel/log',"get",()=>{
    console.log("Mock调用: 获取Kernel日志");

    return {
        code: 0,
        data: "3,3160950,166290794735,c7,-,caller=T414;ap watchdog sprd_wdt_fiq start: timeout = 40, pretimeout = 20\n" +
            "6,3160951,166290794741,c7,-,caller=T414;sprd_wdt: sprd wdt load value timeout =40, pretimeout =20\n" +
            "3,3160955,166291392140,c4,-,caller=T23327;=== virtual_thm_get_temp,i=0,name virtual-sensor@0,max_temp -40000,tz_list->temp36725\n" +
            "3,3160956,166291392151,c4,-,caller=T23327;=== virtual_thm_get_temp,i=1,name virtual-sensor@0,max_temp 36725,tz_list->temp36725\n" +
            "3,3160957,166291392169,c4,-,caller=T23327;=== virtual_thm_get_temp,i=2,name virtual-sensor@0,max_temp 36725,tz_list->temp36725\n" +
            "3,3160958,166291392181,c4,-,caller=T23327;=== virtual_thm_get_temp,i=3,name virtual-sensor@0,max_temp 36725,tz_list->temp36583\n" +
            "3,3160959,166291392191,c4,-,caller=T23327;=== virtual_thm_get_temp,i=4,name virtual-sensor@0,max_temp 36725,tz_list->temp36333\n" +
            "3,3160960,166291392200,c4,-,caller=T23327;=== virtual_thm_get_temp,i=5,name virtual-sensor@0,max_temp 36725,tz_list->temp36083\n" +
            "3,3160961,166291392209,c4,-,caller=T23327;=== virtual_thm_get_temp,i=6,name virtual-sensor@0,max_temp 36725,tz_list->temp36333\n" +
            "3,3160962,166291392217,c4,-,caller=T23327;=== virtual_thm_get_temp,i=7,name virtual-sensor@0,max_temp 36725,tz_list->temp36204\n" +
            "3,3160963,166291392226,c4,-,caller=T23327;=== virtual_thm_get_temp,i=8,name virtual-sensor@0,max_temp 36725,tz_list->temp36092\n" +
            "3,3160964,166291392230,c4,-,caller=T23327;===* virtual_thm_get_temp,name virtual-sensor@0,*temp 36725\n" +
            "4,3160965,166291414532,c6,-,caller=T1786;audit: audit_lost=1728228 audit_rate_limit=5 audit_backlog_limit=64\n" +
            "3,3160966,166291414535,c6,-,caller=T1786;audit: rate limit exceeded"
    };
})

// system log
Mock.mock("/api/system/log", "get",()=>{
    return {
        code: 0,
        data: "1,3160961,166291392230,c4,-,caller=T23327;===* virtual_thm_get_temp,name virtual-sensor@0,*temp 36725\n" +
            "2,3160962,166291392230,c4,-,caller=T23327;===* virtual_thm_get_temp,name virtual-sensor@0,*temp 36725\n"
    };
})

Mock.mock("/api/system/log/config", "get",()=>{
    return {
        code: 0,
        data: {
            "level": "debug",
            "type": "all"
        }
    };
})

Mock.mock("/api/system/log/config", "post",(params)=>{
    console.log('Mock调用: 保存日志类型',  JSON.parse(params.body));
    return {
        code: 0,
        data: ""
    };
})

Mock.mock("/api/system/ping", "post",(params)=>{ 
    console.log('Mock调用: 保存日志类型',  JSON.parse(params.body));
    return {
        code: 0,
        data: "PING www.a.shifen.com (157.148.69.151) 56(84) bytes of data.\n" +
            "64 bytes from 157.148.69.151: icmp_seq=1 ttl=52 time=46.2 ms\n" +
            "64 bytes from 157.148.69.151: icmp_seq=2 ttl=52 time=45.2 ms\n" +
            "64 bytes from 157.148.69.151: icmp_seq=3 ttl=52 time=43.5 ms\n" +
            "64 bytes from 157.148.69.151: icmp_seq=4 ttl=52 time=43.6 ms\n" +
            "^C\n" +
            "--- www.a.shifen.com ping statistics ---\n" +
            "12 packets transmitted, 12 received, 0% packet loss, time 11015ms\n" +
            "rtt min/avg/max/mdev = 39.503/44.100/54.495/3.629 ms"
    };
})

    let usageState = { 
        currentUsage: 133,
        currentAllowance: 1133000,
        step: 5 // 基础变化步长
    };
   let lanInfo = {
        // DHCP 配置
        ip_address: "192.168.1.1",       
        net_mask: "255.255.255.0",       
        dhcp_enable: true,               
        dhcp_range_start: "192.168.1.100",
        dhcp_range_end: "192.168.1.200",
        dhcp_lease_time: 86400,   
   }

    let netSetting = {
        select_mode: "auto_select", // ('manual_select'：表示手动选择模式、'auto_select':自动选择模式)
        network_mode: "lte", // 网络类型（实际值：4G LTE）
        data_roaming_enable: true, // 数据漫游开关（实际值：开启）
        mobile_data_enable: true, // 移动数据开关（实际值：开启）
        wan_nat: true,
   }

    let apnInfo={
           defaultId : '1',
           apnList:[ 
                {
                    profile_id: 'apn_001',               // 示例值
                    enable: '1',                 // 是否启用（'1' 表示启用）
                    label: 'CMNET1',              // 标签名称
                    name: 'cmtd1',          // APN 名称
                    auth_type: 'PAP',             // 认证类型
                    username: 'user123',         // 用户名
                    password: 'pass456',         // 密码
                    pdn_type: 'IPV4',             // PDN 类型
                    manage_interface: 'eth0',     // 管理接口
                    mac: '00:11:22:33:44:55',    // MAC 地址
                    vid: '100',                  // VLAN ID
                    mtu: '1500',                 // MTU 值
                    ippt: 'default',             // IP 参数类型   
                },
                {
                    profile_id: 'apn_002',               // 示例值
                    enable: '1',                 // 是否启用（'1' 表示启用）
                    label: 'CMNET2',              // 标签名称
                    name: 'cmtd2',          // APN 名称
                    auth_type: 'PAP',             // 认证类型
                    username: 'user123',         // 用户名
                    password: 'pass456',         // 密码
                    pdn_type: 'IPV4',             // PDN 类型
                    manage_interface: 'eth0',     // 管理接口
                    mac: '00:11:22:33:44:55',    // MAC 地址
                    vid: '100',                  // VLAN ID
                    mtu: '1500',                 // MTU 值
                    ippt: 'default',             // IP 参数类型   
                },
                {
                    profile_id: 'apn_003',               // 示例值
                    enable: '1',                 // 是否启用（'1' 表示启用）
                    label: 'CMNET3',              // 标签名称
                    name: 'cmtd',                 // APN 名称
                    auth_type: 'PAP',             // 认证类型
                    username: 'user123',         // 用户名
                    password: 'pass456',         // 密码
                    pdn_type: 'IPV4',             // PDN 类型
                    manage_interface: 'eth0',     // 管理接口
                    mac: '00:11:22:33:44:55',    // MAC 地址
                    vid: '100',                  // VLAN ID
                    mtu: '1500',                 // MTU 值
                    ippt: 'default',             // IP 参数类型   
                }
            ]
    }
 
     Mock.mock('/api/mobile/internet', 'get', () => {
        console.log("Mock调用: 获取internet 信息");
        let result = getRandomRate(-111,0);
        return {
            code: 0,
            data: {            
                // Internet 设置信息
                select_mode: netSetting.select_mode, // 手动/自动选择模式（实际值：自动选择）
                network_mode: netSetting.network_mode, // 网络类型（实际值：4G LTE）
                data_roaming_enable:netSetting.data_roaming_enable, // 数据漫游开关（实际值：开启）
                mobile_data_enable: netSetting.mobile_data_enable, // 移动数据开关（实际值：开启）
                wan_nat: netSetting.wan_nat,
                
                // Internet 连接信息
                connected_time: 3300, // 连接时长（秒，实际值：1小时）
                ezmesh_role: "agent", // EZmesh角色（实际值：客户端模式）
                wan_enable: true, // WAN使能（实际值：启用）
                apn_apply_num: apnInfo.apnList[apnInfo.defaultId - 1].profile_id, // APN应用编号（随机8位字符串，实际值：运营商默认APN）
                
                // IPv4 配置
                ipv4_enable: true, // IPv4使能（实际值：启用）
                ip_address: "192.168.1.100", // IPv4地址（实际值：家用网关内网IP）
                gateway: "192.168.1.1", // IPv4网关（实际值：家用路由器网关）
                primary_dns_server: "8.8.8.8", // 主DNS服务器（IPv4，实际值：Google公共DNS）
                secondary_dns_server: "8.8.4.4", // 备用DNS服务器（IPv4，实际值：Google公共DNS备用）
                
                // IPv6 配置
                ipv6_enable: true, // IPv6使能（实际值：启用）
                ip_address_ipv6: "2001:db8::1", // IPv6地址（实际值：临时测试地址）
                gateway_ipv6: "2001:db8::ff", // IPv6网关（实际值：网关IPv6地址）
                primary_dns_server_ipv6: "2001:4860:4860::8888", // DNS服务器（IPv6，实际值：Google IPv6 DNS）
                secondary_dns_server_ipv6: "2001:4860:4860::8844", // 备用DNS服务器（IPv6）
                
                //sim
                sim_status: "connected",
                local_phone_number:"1234567890",
                signal_strength: result,
            }
        };
    });

     Mock.mock("/api/mobile/internet","post",(params)=>{ 
        console.log('Mock调用: 更新internet设置',  JSON.parse(params.body));
        const body = JSON.parse(params.body)
        console.log("network_mode1",body.network_mode);
        if (body.network_mode) {
            const mode = body.network_mode
             switch (mode) {
                    case '5G':
                    netSetting.network_mode = 'nr';    // 5G网络
                    break;
                    case '4G':
                    netSetting.network_mode = 'lte';    // 4G网络
                    break;
                    case '3G':
                    netSetting.network_mode = 'wcdma';    // 3G网络（WCDMA）
                    break;
                    default:
                    netSetting.network_mode = '';  
                }
            
            
        }
        if (params.body.data_roaming_enable){ 
            netSetting.data_roaming_enable = body.data_roaming_enable;
        } 
        if (params.body.mobile_data_enable){
           netSetting.mobile_data_enable = body.mobile_data_enable;
        } 
        if (params.body.wan_nat){
            netSetting.wan_nat = body.wan_nat;
        }  


        console.log('lanInfo', netSetting);
        return {
            code: 0,
            data: {
                result: 'success'
            }
        }
    })
    Mock.mock('/api/mobile/profile', 'get', () => {
        console.log("Mock调用: 获取profile信息");
        return {
            code: 0,
            data: { 
               default_id:apnInfo.defaultId,
               apn_list: apnInfo.apnList,
        }
            
        };
    });
    Mock.mock("/api/mobile/profile/modify","post",(params)=>{ 
            console.log('Mock调用: update apnInfo by id',  JSON.parse(params.body));
            
            return {
                code: 0,
                data: {
                    result: 'success'
                }
            }
        })

         Mock.mock("/api/mobile/profile/default","post",(params)=>{ 
            console.log('Mock调用: 设置默认apn',  JSON.parse(params.body));
            apnInfo.defaultId = JSON.parse(params.body).default_id
            return {
                code: 0,
                data: {
                    result: 'success'
                }
            }
        })


    Mock.mock('/api/mobile/lan', 'get', () => {
        console.log("Mock调用: 获取LAN信息");
        return {
            code: 0,
            data: {            
                ip_address: lanInfo.ip_address,       
                net_mask: lanInfo.net_mask,       
                dhcp_enable: lanInfo.dhcp_enable,               
                dhcp_range_start: lanInfo.dhcp_range_start,
                dhcp_range_end: lanInfo.dhcp_range_end,
                dhcp_lease_time: lanInfo.dhcp_lease_time,   
            }
        };
    });

    Mock.mock('/api/mobile/role', 'get', () => {
    console.log("Mock调用: 获取ezmesh_role");
    return {
        code: 0,
        data: {            
            ezmesh_role:'agent',//( 'agent' 、 'Agent') 
        }
    };
});

Mock.mock('/api/mobile/lan', 'get', () => {
    console.log("Mock调用: 获取LAN信息");
    return {
        code: 0,
        data: {            
            ip_address: lanInfo.ip_address,       
            net_mask: lanInfo.net_mask,       
            dhcp_enable: lanInfo.dhcp_enable,               
            dhcp_range_start: lanInfo.dhcp_range_start,
            dhcp_range_end: lanInfo.dhcp_range_end,
            dhcp_lease_time: lanInfo.dhcp_lease_time,   
        }
    };
});

    Mock.mock("/api/mobile/lan","post",(params)=>{ 
    console.log('Mock调用: 设置LAN信息',  JSON.parse(params.body));
    
    lanInfo = params.data;
    return {
        code: 0,
        data: {
            result: 'success'
        }
    }
})


Mock.mock('/api/cellular/info', 'get', () => {
    console.log("Mock调用: 获取cellular信息");
    // 生成动态数据
    const newUsage = usageState.currentUsage + getRandomStep(1, 3);
    const newAllowance = Math.max(0, usageState.currentAllowance - getRandomStep(1, 3));
    
    // 生成随机速率（范围可自定义）
    const uplinkRate = getRandomRate(1, 2000);  // 1-2000 kbps
    const downlinkRate = getRandomRate(1, 3000); // 1-3000 kbps
            
    // 更新状态
    usageState.currentUsage = newUsage;
    usageState.currentAllowance = newAllowance;

    return {
        code: 0,
        data: {
            enable: true,
            limit_mode: "monthly",
            data_usage: newUsage,
            data_allowance: newAllowance,
            uplink_rate: uplinkRate,
            downlink_rate: downlinkRate
        }
    };
});
    Mock.mock('/api/wireless/info', 'get', () => {
    console.log("Mock调用: 获取wireless信息");
    return {
        code: 0,
        data: {            
            "band2_4": {
                "enable": true,
                "ssid": "2.4G_WiFi",
                "password": "12345678",
                "encryption_mode": "wpa2aes",
                "channel": 6
            },
            "band5": { 
                "enable": true,
                "ssid": "5G_WiFi",
                "password": "88888",
                "encryption_mode": "wpa2aes",
                "channel": 40
            }
        }
    };
});



Mock.mock('/api/wireless/default','get',(params)=>{
    return {
        code:0,
        data:{
            "isdba" : false,
             support_encryption: JSON.stringify({
            "none": "No Security",
            "wpa2aes": "WPA2-PSK",
            "wpa3sae": "WPA3-SAE"
             }),
            // 2.4G备份数据
            ssid_24g: 'MyWiFi_2.4G',
            key_24g: 'password123',
            encryption_24g: 'wpa2aes',
            // 5G备份数据
            ssid_5g: 'MyWiFi_5G',
            key_5g: 'password123',
            encryption_5g: 'wpa2aes'
        }
    }
})


Mock.mock("/api/sms/readable","get",(params)=>{
    return {
        code: 0,
        data: {
            unread:0,
            full:300,
            current:50
        }
    };
})

Mock.mock("/api/quick/setting","post",(params)=>{ 
    console.log('Mock调用: 保存快速设置',  JSON.parse(params.body));
    return {
        code: 0,
        data: ""
    }
})
var first_login = 0
Mock.mock("/api/auth/first","get",(params)=>{
    return {
        code: 0,
        data: {
            first_login: first_login
        }
    }
})

Mock.mock("/api/auth/first","post",(params)=>{
    first_login = 0;
    return {
        code: 0,
        data: ""
    }
})

var pin_lock = false;
Mock.mock("/api/pin/setting","get",(params)=>{ 
    console.log('Mock调用: 获取pin设置');
    return {
        code: 0,
        data: {
            pin_lock: pin_lock,
            pin_code: "333333",
            sim_status: "sim_locked",
            remaining_unlock_trial: 5,
            auto_pin: false
        }
    }
})

Mock.mock("/api/pin/verify","post",(params)=>{
    console.log('Mock调用: 验证pin',  JSON.parse(params.body));
    pin_lock = false;
    return {
        code: 0,
        data: ""
    }
})

Mock.mock("/api/auth/update","post",(params)=>{ 
    return {
        code:0,
        data: ""
    }
})
